<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class mod_menu extends CI_Model {
    
    function __construct()
    {
        parent::__construct();
    }

    public function insert_menu()
    {
        $data['nombre'] = $this->input->post('nombre');
        $data['titulo'] = $this->input->post('titulo');
        $data['controlador'] = $this->input->post('controlador');
        $data['metodo'] = $this->input->post('metodo');
        $data['id_menu_padre'] = $this->input->post('id_menu_padre');
        $data['estado']=1;
        $data['order'] = $this->input->post('order');
        $this->db->insert('menu',$data);                        
    }
    
    public function update_menu()
    {
        $data['nombre'] = $this->input->post('nombre');
        $data['titulo'] = $this->input->post('titulo');
        $data['controlador'] = $this->input->post('controlador');
        $data['metodo'] = $this->input->post('metodo');
        $data['id_menu_padre'] = $this->input->post('id_menu_padre');
        $data['estado']=1;
        $data['order'] = $this->input->post('order');
        $this->db->where('menu.id_menu',$this->input->post('id_menu'));
        $this->db->update('menu',$data);	
    }
    
    public function delete_menu($id_menu)
    {
        $this->db->where('menu.id_menu',$id_menu );
        $this->db->delete('menu');
    }
    
    public function carga_tabla()
    {          
       	return $this->db->query("
            SELECT menu.id_menu,
                menu.nombre,
                menu.titulo,
                menu.controlador,
                menu.metodo,
                menu.id_menu_padre,
                menu.estado,
                menu.order
            FROM
                menu");
    }
    
    public function carga_datos($id_menu)
    {          
       	return $this->db->query("
            SELECT menu.id_menu, 
                menu.nombre,
                menu.titulo,
                menu.controlador,
                menu.metodo,
                menu.id_menu_padre,
                menu.order
            FROM
                menu
            WHERE menu.id_menu='".$id_menu."' LIMIT 1");   
    }
}